<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
require_once('./includes/common.php');
$site_list_top = $DB->findAll('site', 'id,name,img,alias', array('tui' => '1'), 'lid asc', 12);
$notice = $DB->find('notice', 'content', '', 'id desc');
$cate_list = $DB->findAll('category', '*', '', 'sid asc');
updateRefererIn();
$site_list_drtime = $DB->findAll('site', 'id,name,img', '', 'drtime desc', 14);
$site_list_rank = $DB->findAll('site', 'id,alias,name,img,hits_total', null, 'hits_total desc', 10);
$site_list_time = $DB->findAll('site', 'id,alias,name,img,time', null, 'time desc', 6);
$article_cate_list = $DB->findAll('article_category', 'id,catename,icon', null, 'sid asc');
$article_list_time = $DB->findAll('article', 'id,name', null, 'time desc', 5);
$link_list = $DB->findAll('link', 'url,name,img', null, 'id asc', 20);
$article_list_suggest = $DB->findAll('article', 'id,name,hits_total,time,introduce,cover', 'tui=1', 'time desc', 8);
$page_title = $conf['title'];
if (!empty($conf['subtitle'])) {
    $page_title .= ' - ' . $conf['subtitle'];
}
require_once('./includes/lang.class.php');
?>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no">
        <title><?php echo $page_title; ?></title>
        <!-- 基础SEO元标签 -->
        <meta name="keywords" content="<?php echo $conf['keywords'];?>">
        <meta name="description" content="<?php echo $conf['description'];?>">
        <meta name="author" content="<?php echo $conf['name'] ?>,<?php echo $conf['email'] ?>" />
        <meta name="robots" content="index, follow" />
        
        <!-- Open Graph协议 - 提升社交媒体分享效果 -->
        <meta property="og:type" content="website" />
        <meta property="og:title" content="<?php echo $page_title; ?>" />
        <meta property="og:description" content="<?php echo $conf['description'];?>" />
        <meta property="og:url" content="<?php echo $site_url ?>" />
        <meta property="og:site_name" content="<?php echo $conf['name'] ?>" />
        <meta property="og:locale" content="zh_CN" />
        
        <!-- Twitter Cards -->
        <meta name="twitter:card" content="summary_large_image" />
        <meta name="twitter:title" content="<?php echo $page_title; ?>" />
        <meta name="twitter:description" content="<?php echo $conf['description'];?>" />
        
        <!-- 搜索引擎验证 -->
        <!-- 可以在这里添加百度、谷歌等搜索引擎的验证代码 -->
        <!-- <meta name="baidu-site-verification" content="your_baidu_verification_code" /> -->
        <!-- <meta name="google-site-verification" content="your_google_verification_code" /> -->
        
        <!-- 网站图标 -->
        <link rel="shortcut icon" type="image/x-icon" href="./favicon.ico"/>
        <link rel="icon" href="./favicon.ico" type="image/x-icon" />
        
        <!-- 样式表 -->
        <link rel="stylesheet" href="<?php echo $site_cdnpublic; ?>font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="./assets/css/ozui.min.css"/>
        <link rel="stylesheet" type="text/css" href="./templates/<?php echo $conf['theme'] ? $conf['theme'] : 'default'; ?>/css/style.css"/>
        <link rel="stylesheet" type="text/css" href="./templates/<?php echo $conf['theme'] ? $conf['theme'] : 'default'; ?>/css/stats.css"/>
        <link rel="stylesheet" type="text/css" href="./templates/<?php echo $conf['theme'] ? $conf['theme'] : 'default'; ?>/css/background.css"/>
        
        <!-- 预加载关键资源 -->
        <link rel="preload" href="<?php echo $site_cdnpublic; ?>jquery/1.12.4/jquery.min.js" as="script" />
        
        <!-- jQuery库 -->
        <script type="text/javascript" src="/assets/jquery/1.12.4/jquery.min.js"></script>
        
        <?php echo $conf['script_header']; ?>

    </head>
<body>
<div class="background-container"></div>
<style>
    .board-notice {
        color: #0000ff;
        font-weight: bold;
    }
    .notice-title {
        font-weight: bold;
        color: #ff0000;
    }
</style>
<?php require('./home/header.php'); ?>
<?php require('./home/banner.php'); ?>

<ul class="category">
    <li><a href="#置顶站点" class="move"><span>置顶推荐</span> <i class="fa fa-thumbs-o-up fa-fw"></i></a></li>
<?php foreach($cate_list as $rows) { ?>
    <li><a href="#<?php echo $rows['catename']; ?>" class="move"><span><?php echo $rows['catename']; ?></span> <i class="fa <?php echo $rows['icon']; ?> fa-fw"></i></a></li>
<?php } ?>
</ul>

<div class="container">
    <div class="main">
        <div class="card board">
            <span class="icon"><span class="notice-title">公告通知</span> <i class="fa fa-bullhorn fa-fw" style="font-weight: bold;"></i></span>
            <marquee scrollamount="4" behavior="scroll" onmouseover="this.stop()" onmouseout="this.start()">
                <span class="board-notice"><?php echo $notice['content']; ?></span>
            </marquee>
        </div>

        <!-- 数据统计卡片 -->
        <div class="card">
            <div class="card-body">
                <div class="stat-container">
                    <div class="stat-item">
                        <div class="stat-value"><?php echo $DB->count('site'); ?></div>
                        <div class="stat-name">已收录站点</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value"><?php echo $DB->count('apply', array('reject' => 0)); ?></div>
                        <div class="stat-name">待审核站点</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value"><?php echo $DB->count('apply', array('reject' => 1)); ?></div>
                        <div class="stat-name">已拒绝站点</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value"><?php echo $DB->count('article'); ?></div>
                        <div class="stat-name">文章数</div>
                    </div>
                </div>
            </div>
        </div>
        


        <div class="card">
            <div class="wzgg">
                <a href="#" target="_blank" rel="nofollow">文字广告火爆招租</a>
                <a href="#" target="_blank" rel="nofollow">文字广告火爆招租</a>
                <a href="#" target="_blank" rel="nofollow">文字广告火爆招租</a>
                <a href="#" target="_blank" rel="nofollow">文字广告火爆招租</a>
            </div>
        </div>

        <div id="置顶站点" class="card">
            <div class="card-head">
                <i class="fa fa-thumbs-o-up fa-fw" style="font-weight: bold; color: #ff0000;"></i><span style="font-weight: bold; color: #ff0000;">置顶推荐</span>
            </div>
            <div class="card-body">
            <div class="top-grid">
            <?php foreach($site_list_top as $rows) { ?>
                <a href="<?php echo empty($rows['alias']) ? $site_url . '/site/' . $rows['id'] . '.html' : $site_url . '/site/' . $rows['alias'] . '.html'; ?>" class="item" title="<?php echo $rows['name']; ?>" data-id="<?php echo $rows['id']; ?>">
                    <span class="icon"><img class="lazy-load" src="/assets/images/loading.gif" data-src="<?php echo $rows['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                    <span class="name"><?php echo $rows['name']; ?></span>
                </a><?php } ?>
            </div>
            </div>
        </div>

        <!-- <div class="card">
            <a class="ad" target="blank" href="apply.html">
                <img src="assets/images/2.gif">
            </a>
        </div> -->

        <div class="card">
            <div class="card-head">
                <i class="fa fa-link fa-fw"></i>友链后在贵站点击本站即排本站首位
            </div>
            <div class="card-body">
                <?php foreach($site_list_drtime as $rows) { ?>
                <a href="<?php echo $site_url; ?>/site/<?php echo $rows['id']; ?>.html" target="_blank" class="item" title="<?php echo $rows['name']; ?>" data-id="<?php echo $rows['id']; ?>">
                    <span class="icon"><img class="lazy-load" src="assets/images/loading.gif" data-src="<?php echo $rows['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                    <span class="name"><?php echo $rows['name']; ?></span>
                </a>
                <?php } ?>

            </div>
        </div>

        <!-- 最新收录卡片 -->
        <div class="card">
            <div class="card-head">
                <i class="fa fa-clock-o fa-fw"></i>最新收录<a href="<?php echo $site_url; ?>/apply.html" class="more"><i class="fa fa-plus-square" aria-hidden="true"></i>申请收录</a>
            </div>
            <div class="card-body">
                <?php foreach($site_list_time as $rows) { ?>
                <a href="<?php echo empty($rows['alias']) ? $site_url . '/site/' . $rows['id'] . '.html' : $site_url . '/site/' . $rows['alias'] . '.html'; ?>" target="_blank" class="item" title="<?php echo $rows['name']; ?>" data-id="<?php echo $rows['id']; ?>">
                    <span class="icon"><img class="lazy-load" src="assets/images/loading.gif" data-src="<?php echo $rows['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                    <span class="name"><?php echo $rows['name']; ?></span>
                    <span class="time">收录时间: <?php echo $rows['time']; ?></span>
                </a>
                <?php } ?>
            </div>
        </div>

        <?php foreach ($cate_list as $row) { ?>
        <div id="<?php echo $row['catename']; ?>" class="card">
            <div class="card-head">
                <i class="fa <?php echo $row['icon']; ?> fa-fw"></i><?php echo $row['catename']; ?>
                <a href="<?php echo empty($row['alias']) ? $site_url . '/category-' . $row['id'] . '.html' : $site_url . '/category-' . $row['alias'] . '.html'; ?>" class="more"><i class="fa fa-ellipsis-h fa-fw"></i></a>
            </div>
            <div class="card-body">
                <?php $site_list = $DB->findAll('site', 'id,name,alias,img', array('catename' => $row['catename']), 'lid asc', 14);
                foreach ($site_list as $rows) { ?>
                <a href="<?php echo empty($rows['alias']) ? $site_url . '/site/' . $rows['id'] . '.html' : $site_url . '/site/' . $rows['alias'] . '.html'; ?>" target="_blank" class="item" title="<?php echo $rows['name']; ?>" data-id="<?php echo $rows['id']; ?>">
                    <span class="icon"><img class="lazy-load" src="assets/images/loading.gif" data-src="<?php echo $rows['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                    <span class="name"><?php echo $rows['name']; ?></span>
                </a><?php } ?>

            </div>
        </div>
        <?php } ?>

        <div class="card">
            <div class="card-head">
                <i class="fa fa-book fa-fw"></i>文章推荐
                <a href="<?php echo $site_url; ?>/article.html" class="more"><i class="fa fa-ellipsis-h fa-fw"></i></a>
            </div>
            <div class="card-body"><?php foreach($article_list_suggest as $rs) {
                // 优先使用封面图字段
                $imgsrc = !empty($rs['cover']) ? $rs['cover'] : '';
                // 如果没有封面图，再从内容中提取
                if (!$imgsrc) {
                    preg_match_all("|<img[^>]+src=\"([^>\"]+)\"?[^>]*>|is", $rs['introduce'], $img);
                    $imgsrc = !empty($img[1]) ? $img[1][0] : './assets/images/no.png';
                }
            ?>
                <a href="<?php echo $site_url; ?>/article-<?php echo $rs['id']; ?>.html" target="_blank" class="post">
                    <div class="pic">
                        <img class="lazy-load" src="./assets/images/loading.gif" data-src="<?php echo $imgsrc; ?>">
                    </div>
                    <div class="text">
                        <div class="title"><?php echo $rs['name']; ?></div>
                        <div class="info">
                            <span><i class="fa fa-eye fa-fw"></i><?php echo $rs['hits_total']; ?></span>
                            <span><i class="fa fa-clock-o fa-fw"></i><?php echo $rs['time']; ?></span>
                        </div>
                    </div>
                </a>
            <?php } ?>
            </div>
        </div>
    </div>

    <div class="side">
        <!-- 侧边栏广告 - 根据配置显示 -->
        <?php if(isset($conf['sidebar_ad_show']) && $conf['sidebar_ad_show'] == 1): ?>
        <div class="card">
            <div class="card-head"><i class="fa fa-coffee fa-fw"></i><?php echo isset($conf['sidebar_ad_desc']) ? $conf['sidebar_ad_desc'] : ''; ?></div>
            <div class="card-body">
                  <a href="<?php echo isset($conf['sidebar_ad_url']) ? $conf['sidebar_ad_url'] : '#'; ?>" target="_blank" rel="nofollow">
                      <img class="lazy-load ad-responsive" src="assets/images/loading.gif" data-src="<?php echo file_exists('assets/images/sidebar_ad.png') ? 'assets/images/sidebar_ad.png' : 'https://www.sukuy.com/logo.png'; ?>" style="width:100%;border-radius: 5px;">
                  </a>
            </div>
        </div>
        <style>
            /* 广告图片响应式样式 */
            .ad-responsive {
                display: block;
                max-width: 100%;
                height: auto;
                transition: all 0.3s ease;
            }
            
            /* 在小屏幕上调整广告容器的边距和内边距 */
            @media (max-width: 768px) {
                .card {
                    margin-bottom: 15px !important;
                }
                .card-body {
                    padding: 8px !important;
                }
            }
        </style>
        <?php endif; ?>
        
        <div class="card">
            <div class="card-head"><i class="fa fa-line-chart fa-fw"></i>总浏览TOP10</div>
            <div class="card-body">
                <div class="view-list">
                <?php foreach ($site_list_rank as $index => $row ) { ?>
                    <a href="<?php echo empty($row['alias']) ? $site_url . '/site/' . $row['id'] . '.html' : $site_url . '/site/' . $row['alias'] . '.html';?>" data-id="<?php echo $row['id']; ?>">
                        <span class="rank"><?php echo $index + 1; ?></span>
                        <span class="icon"><img class="lazy-load" src="assets/images/loading.gif" data-src="<?php echo $row['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                        <span class="name"><?php echo $row['name']; ?></span>
                        <span class="view"><?php echo $row['hits_total']; ?></span>
                    </a><?php } ?>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-head"><i class="fa fa-coffee fa-fw"></i>最新收录</div>
            <div class="card-body">
                <div class="side-latest oz-timeline">
                    <?php foreach ($site_list_time as $index => $row ) { ?>
                    <a href="<?php echo empty($row['alias']) ? $site_url . '/site/' . $row['id'] . '.html' : $site_url . '/site/' . $row['alias'] . '.html'; ?>"
                        data-id="<?php echo $row['id']; ?>"
                    class="oz-timeline-item">
                        <div class="oz-timeline-time"><?php echo $row['time']; ?></div>
                        <div class="oz-timeline-main">
                            <span class="icon"><img class="lazy-load" src="assets/images/loading.gif" data-src="<?php echo $row['img']; ?>" onerror="this.src='./assets/images/default_ico.png';this.onerror=null;" onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';}" style="min-width:16px;min-height:16px;"></span>
                            <span class="name"><?php echo $row['name']; ?></span>
                        </div>
                    </a><?php } ?>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-head"><i class="fa fa-folder-open fa-fw"></i>文章分类</div>
            <div class="card-body">
                <div class="side-category">
                <?php foreach ($article_cate_list as $row ) { ?>
                    <a href="<?php echo $site_url; ?>/article-list-<?php echo $row['id']; ?>.html" class="">
                        <i class="fa fa-pencil-square-o <?php echo $row['icon']; ?>"></i> <?php echo $row['catename']; ?></a>
                <?php } ?>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-head"><i class="fa fa-bar-chart fa-fw"></i>最新文章</div>
            <div class="card-body">
                <div class="view-list">
                <?php foreach ($article_list_time as $index => $row ) { ?>
                    <a href="<?php echo $site_url; ?>/article-<?php echo $row['id']; ?>.html" target="_blank" title="<?php echo $row['name']; ?>" data-id="<?php echo $row['id']; ?>">
                        <span class="rank"><?php echo $index + 1; ?></span>
                        <span class="name"><?php echo $row['name']; ?></span>
                    </a>
                <?php } ?>
                </div>
            </div>
        </div>

        <!-- <div class="card">
            <a class="ad" target="blank" href="apply.html">
                <img src="assets/images/3.gif">
            </a>
        </div> -->

        <div class="card">
            <div class="card-head"><i class="fa fa-pie-chart fa-fw"></i>本站统计</div>
            <div class="card-body">
                <div class="side-common"><?php require('./home/statistics.php'); ?></div>
            </div>
        </div>
    </div>

    <div class="card links">
            <div class="card-head"><i class="fa fa-link fa-fw"></i>友情链接</div>
            <div class="card-body">
        <?php foreach ($link_list as $rows ) {
            
            $domain = parse_url($rows['url'], PHP_URL_HOST);
            if(!$domain) $domain = $rows['url'];
            
            $favicon = './favicon.php?url=' . urlencode($domain);
            if(!empty($rows['img'])) {
                $favicon = $rows['img'];
            }
            
            $linkId = 'link-' . md5($domain);
        ?>
        <a href="<?php echo $rows['url']; ?>" target="_blank" class="link-item">
            <span class="link-icon">
                <img 
                    id="<?php echo $linkId; ?>" 
                    class="lazy-load" 
                    src="assets/images/loading.gif" 
                    data-src="<?php echo $favicon; ?>" 
                    data-default="assets/images/default_ico.png"
                    alt="<?php echo $rows['name']; ?>" 
                    onerror="this.src='./assets/images/default_ico.png';this.onerror=null;this.classList.add('load-failed');" 
                    onload="if(this.width == 1 && this.height == 1) {this.src='./assets/images/default_ico.png';this.classList.add('load-failed');}"
                    style="min-width:16px;min-height:16px;"
                >
            </span>
            <span class="link-name"><?php echo $rows['name']; ?></span>
        </a>
        <?php } ?>
        </div>
    </div>
    
    <!-- 友情链接图标额外处理脚本 -->
    <script>
    $(function() {
        // 为友情链接区域的图标添加额外的错误处理
        setTimeout(function() {
            $('.card.links .link-icon img').each(function() {
                // 检查是否已经成功加载
                if (!$(this).hasClass('load-failed') && $(this).attr('src') === 'assets/images/loading.gif') {
                    // 先尝试重新加载一次，再考虑使用默认图标
                    var originalSrc = $(this).attr('data-src');
                    var img = new Image();
                    img.onload = function() {
                        // 如果成功加载，更新原图片
                        $(this).attr('src', originalSrc);
                    };
                    img.onerror = function() {
                        // 如果仍然失败，使用默认图标
                        $(this).attr('src', $(this).attr('data-default'));
                        $(this).addClass('load-failed');
                    };
                    img.src = originalSrc;
                }
            });
        }, 5000); // 增加到5秒后检查，给更多时间加载图标
        
        // 重新触发懒加载处理
        if (typeof lazyRender === 'function') {
            // 延迟执行以确保DOM已完全加载
            setTimeout(function() {
                lazyRender($('.lazy-load'));
            }, 500);
        }
    });
    </script>
    
    <style>
        /* 最新收录卡片样式 */
        .card .card-body .item .time {
            font-size: 12px;
            color: #999;
            margin-left: 10px;
        }
        
        /* 友情链接样式 */
        .card.links .card-body {
            padding: 15px;
        }
        .link-item {
            display: inline-flex;
            align-items: center;
            padding: 5px 10px;
            margin: 5px;
            text-decoration: none;
            color: #333;
            border-radius: 4px;
            transition: all 0.3s ease;
        }
        .link-item:hover {
            background-color: #f5f5f5;
        }
        .link-icon {
            width: 16px;
            height: 16px;
            margin-right: 5px;
            display: inline-block;
        }
        .link-icon img {
            width: 100%;
            height: 100%;
            border-radius: 2px;
        }
        .link-name {
            white-space: nowrap;
        }
    </style>

</div>

<?php require('./home/footer.php'); ?>

</body>
</html>